public class demo1 {
      public class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 }
    public ListNode addTwoNumbers1(ListNode l1, ListNode l2) {
        ListNode cut = new ListNode();
        ListNode cur1 = l1;
        ListNode cur2 = l2;
        ListNode cuts = cut;
        while (cur1 != null && cur2 != null) {
            cuts.val = (cur1.val + cur2.val) % 10;
            ListNode cur = new ListNode();
            cuts.next = cur;
            cur1 = cur1.next;
            cur2 = cur2.next;
        }
        while (cur1 != null) {
            cuts.val = cur1.val % 10;
            ListNode cur = new ListNode();
            cuts.next = cur;
            cur1 = cur1.next;
        }
        while (cur2 != null) {
            cuts.val = cur2.val % 10;
            ListNode cur = new ListNode();
            cuts.next = cur;
            cur2 = cur2.next;
        }
        cut=cuts;
        return cut;
    }
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode cur1=l1;
        ListNode cur2=l2;
        ListNode cut=new ListNode();
        int sum=0;
        ListNode newcut=cut;//小技巧不用考虑头节点是否为空
        while(cur1!=null||cur2!=null||sum!=0){
            if(cur1!=null){
                sum+=cur1.val;
                cur1=cur1.next;
            }
            if(cur2!=null){
                sum+=cur2.val;
                cur2=cur2.next;
            }
            ListNode cur=new ListNode(sum%10);
            newcut.next=cur;
            newcut=cur;
            sum/=10;
        }
        return cut.next;
    }

}
